<html>
<head><meta charset="utf-8"><title>MustUse · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html">MustUse</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="197197804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197197804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197197804">(May 11 2020 at 20:07)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="211727">@Jonas Schievink</span> and <span class="user-mention" data-user-id="121053">@varkor</span>  -- could I maybe ask you all a question about <code>MustUse</code></p>



<a name="197197954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197197954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197197954">(May 11 2020 at 20:08)</a>:</h4>
<p>We've had a lot of conversation about it lately, and a few PRs:</p>
<ul>
<li><a href="https://github.com/rust-lang/rust/pull/71816">https://github.com/rust-lang/rust/pull/71816</a> -- <span class="user-mention" data-user-id="211727">@Jonas Schievink</span>'s addition of a <code>MustUse</code> trait</li>
<li><a href="https://github.com/rust-lang/rust/pull/62262">https://github.com/rust-lang/rust/pull/62262</a> -- <span class="user-mention" data-user-id="121053">@varkor</span>'s earlier PR to extend <code>#[must_use]</code> to nested structures (e.g., if any field type is must use)</li>
</ul>



<a name="197198058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197198058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197198058">(May 11 2020 at 20:09)</a>:</h4>
<p>The latter had some <a href="https://github.com/rust-lang/rust/pull/62262#issuecomment-544647401">crater run results</a>, and I think the results were a bit mixed. i.e., it caught some bugs, but also some amount of "false positives".</p>



<a name="197198176"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197198176" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197198176">(May 11 2020 at 20:10)</a>:</h4>
<p>At the same time, particularly around async, this is a helpful lint to catch missing <code>await</code>, with at least a few use cases:</p>
<ul>
<li><code>Pin&lt;MustUseType&gt;</code></li>
<li>`Option&lt;MustUseType&gt;</li>
<li><code>tokio::JoinHandle&lt;MustUseType&gt;</code></li>
</ul>
<p>have been raised.</p>



<a name="197198327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197198327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197198327">(May 11 2020 at 20:11)</a>:</h4>
<p>I feel like it'd be nice to get a bit more data -- for example, I'm curious about a proposal similar to <a href="https://github.com/rust-lang/rust/issues/62262">#62262</a> except that we say that a type <code>SomeType&lt;T0..Tn&gt;</code> is must use if </p>
<ul>
<li><code>SomeType</code>  is tagged <code>#[must_use]</code></li>
<li>any of the types <code>T0..Tn</code> are <code>#[must_use]</code></li>
</ul>
<p>(but we don't look at the fields of <code>SomeType</code>, as <a href="https://github.com/rust-lang/rust/issues/62262">#62262</a> did)</p>
<p>Did we ever try that?</p>



<a name="197198374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197198374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197198374">(May 11 2020 at 20:11)</a>:</h4>
<p>Anyway I was wondering whether either of you was motivated to try and pursue a change here. I think it would probably involve an RFC, although it depends on the magnitude of the change we land on.</p>



<a name="197201236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197201236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197201236">(May 11 2020 at 20:34)</a>:</h4>
<p>So I think that being able to have types be Must Use mostly applies to closures and places where you can't mark the code's output as being must_use? I mean like Felix said in the meeting today, Must Use is really a property of code, not of data? Or, I guess "it should be", even if that's not true in Rust today. It seems like having Must Use on data types is just a shortcut to having Must Use on every function that returns that particular type of data. And then all this difficulty over having it be a trait or recursive or anything else is basically being caused by the fact that Must Use "isn't supposed" to be on data types in the first place?</p>
<p>I guess i'm not trying to favor any particular proposal at all, just asking for clarification on how you see things.</p>



<a name="197202149"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197202149" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197202149">(May 11 2020 at 20:42)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> It's not just "you can't", it's also "you don't want to go to every function and mark it".</p>



<a name="197202162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197202162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197202162">(May 11 2020 at 20:42)</a>:</h4>
<p>For instance, <code>Result</code> being <code>must_use</code> is <em>useful</em>.</p>



<a name="197202400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197202400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197202400">(May 11 2020 at 20:45)</a>:</h4>
<p>I would even go so far as to say that if Result was <em>not</em> must_use, we would be in a significantly worse place wrt to "Rust ensures you check errors" today -- it's more than just useful.</p>



<a name="197202585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197202585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197202585">(May 11 2020 at 20:46)</a>:</h4>
<p>I am in this case ignoring the grunt work of marking each function as must_use individually, yes.</p>



<a name="197202773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197202773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197202773">(May 11 2020 at 20:48)</a>:</h4>
<p>But that's exactly my point really, making Result <code>must_use</code> as a type is just a shortcut for the <em>actual practical effect</em> that people want, which is that code that returns Result values should generally be <code>must_use</code></p>



<a name="197202821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197202821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197202821">(May 11 2020 at 20:49)</a>:</h4>
<p>Yes, that's largely true I think.</p>



<a name="197203180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197203180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197203180">(May 11 2020 at 20:52)</a>:</h4>
<p>Well if we take that as the point of <code>must_use</code> being on a type, having a <code>must_use</code> field make your own type automatically become <code>must_use</code> by default and then adding a field attribute that you can place on a field for "this counts as used, stay quiet about it" if you need to opt out seems like the simplest system to understand as a user.</p>



<a name="197205580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197205580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197205580">(May 11 2020 at 21:13)</a>:</h4>
<p>I don't really think I have the time to pursue an RFC for this (I didn't realize one would be necessary, as I just intended to slightly improve diagnostics without any plans for stabilizing <code>MustUse</code>)</p>



<a name="197205765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197205765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197205765">(May 11 2020 at 21:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/MustUse/near/197198327">said</a>:</p>
<blockquote>
<p>I feel like it'd be nice to get a bit more data -- for example, I'm curious about a proposal similar to <a href="https://github.com/rust-lang/rust/issues/62262">#62262</a> except that we say that a type <code>SomeType&lt;T0..Tn&gt;</code> is must use if </p>
<ul>
<li><code>SomeType</code>  is tagged <code>#[must_use]</code></li>
<li>any of the types <code>T0..Tn</code> are <code>#[must_use]</code></li>
</ul>
<p>(but we don't look at the fields of <code>SomeType</code>, as <a href="https://github.com/rust-lang/rust/issues/62262">#62262</a> did)</p>
<p>Did we ever try that?</p>
</blockquote>
<p>We didn't try that, but this seems quite ad hoc to me. Why should the behaviour of <code>SomeType&lt;Foo&gt;</code> be different to the same type declaration with <code>Foo</code> inlined?</p>



<a name="197205857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197205857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197205857">(May 11 2020 at 21:16)</a>:</h4>
<p>I appreciate it's pragmatically motivated, but this seems special-cased enough that it's sure to be too limited.</p>



<a name="197205903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197205903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197205903">(May 11 2020 at 21:16)</a>:</h4>
<p>A trait to me seems like the best approach, though there are tricky design decisions. Maybe we could write up something detailing the issues with the various approaches?</p>



<a name="197206982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197206982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Asa Zeren <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197206982">(May 11 2020 at 21:28)</a>:</h4>
<p>If we decide to use a trait (which I'm not 100% sold on), then perhaps the way that #[must_use] on functions work is by wrapping the result in a type <code>MustUse&lt;T&gt;</code> that impls MustUse and Deref&lt;T&gt;</p>



<a name="197207071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197207071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197207071">(May 11 2020 at 21:29)</a>:</h4>
<p>I can't seem to see an RFC where <code>must_use</code> was added for types, just the one where it was added for functions.</p>
<p>Particularly, I'd like to see if there was long ago discussion about types other than Result being <code>must_use</code>. And more particularly, a quick ripgrep of just the files i have on this machine shows i've put <code>must_use</code> on at least 675 functions in my own projects, though I don't have all of my projects cloned on to this machine all at once, so it's probably higher than that.</p>



<a name="197208134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197208134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197208134">(May 11 2020 at 21:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/213817-t-lang/topic/MustUse/near/197205857">said</a>:</p>
<blockquote>
<p>I appreciate it's pragmatically motivated, but this seems special-cased enough that it's sure to be too limited.</p>
</blockquote>
<p>A few thoughts:</p>
<ul>
<li>I see a meaningful difference between a <code>Foo&lt;Result&gt;</code> and a <code>Bar</code> that embeds a <code>Result</code>. The latter is incorporating the result and encapsulating it, the former is, via generics, purposefully agnostic about what sort of data it is ferrying about. There is of course also the pragmatic difference that <code>Bar</code> can readily be tagged <code>#[must_use]</code>, if that makes sense, but <code>Foo</code> cannot.</li>
<li>That said, what I'm most interested in here is somebody taking the time to organize some of the patterns and examples and gather a bit more data. e.g., if it's too limited, what are some persuasive examples of code where it would fail to trigger in the wild? Similarly, what are some examples where the lint would trigger but arguably shouldn't? Bonus points if they're generic. </li>
</ul>
<p>I guess that your crater run likely contains all the relevant data, since I think it is a superset of what I proposed, right?</p>



<a name="197214293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197214293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197214293">(May 11 2020 at 22:41)</a>:</h4>
<blockquote>
<p>I guess that your crater run likely contains all the relevant data, since I think it is a superset of what I proposed, right?</p>
</blockquote>
<p>Yes, that's true.</p>



<a name="197214396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197214396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197214396">(May 11 2020 at 22:42)</a>:</h4>
<p>Though maybe it was long ago enough that it won't have picked up so many of the async-related cases.</p>



<a name="197485529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197485529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197485529">(May 13 2020 at 22:31)</a>:</h4>
<p>I don't know if the parallel is useful here, but there's also been discussion of "automatic" <code>[must_use]</code> for functions.  The idea being that a heuristic could catch the vast majority of places where it's be helpful (perhaps using a <code>Freeze</code>-like auto trait).  If functions can sometimes be must-use based on their arguments, it seems plausible that types could also be must-use based on their arguments (if in a rather different way).</p>
<p>(Especially if there was an opt-out form of must_use so said heuristic could have some, though certainly very very few, false positives.)</p>



<a name="197575678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197575678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197575678">(May 14 2020 at 15:51)</a>:</h4>
<p>Side note that, early on in Rust, there was a debate about whether we should make <strong>all</strong> values "must use", so that any unused result not of type <code>()</code> would be warned</p>



<a name="197575701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197575701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197575701">(May 14 2020 at 15:51)</a>:</h4>
<p>We settled on the <code>#[must_use]</code> lint, for better or worse...</p>



<a name="197575833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197575833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197575833">(May 14 2020 at 15:52)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span> is the idea basically to catch things that don't appear to have side-effects and consider them "must use"? Sounds tricky to me, but maybe.</p>



<a name="197576156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197576156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197576156">(May 14 2020 at 15:54)</a>:</h4>
<p>yeah, in particular basically we've recently been applying must_use to "all" functions that are something like <code>fn(T, ...) -&gt; T</code> in std, particularly the integer and float inherent methods</p>



<a name="197576519"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197576519" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197576519">(May 14 2020 at 15:57)</a>:</h4>
<p>One obvious flag for side effect free functions are <code>const fn</code> without <code>&amp;mut</code> or <code>UnsafeCell</code> arguments</p>



<a name="197576735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197576735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197576735">(May 14 2020 at 15:58)</a>:</h4>
<p>yeah, something like that</p>



<a name="197576773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197576773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197576773">(May 14 2020 at 15:58)</a>:</h4>
<p>it's unclear to me that we gain much from avoiding the must_use annotations, though otoh it's kinda similar to Result</p>



<a name="197578302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197578302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197578302">(May 14 2020 at 16:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/213817-t-lang/topic/MustUse/near/197576519">said</a>:</p>
<blockquote>
<p>One obvious flag for side effect free functions are <code>const fn</code> without <code>&amp;mut</code> or <code>UnsafeCell</code> arguments</p>
</blockquote>
<p>However, this isn't 100% fool-proof, since const fns can panic. For example, <code>Result::unwrap</code> should be const once that feature is stable, and it's sometimes called primarily to panic on errors even if the <code>Ok</code> payload isn't relevant.</p>



<a name="197578745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197578745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197578745">(May 14 2020 at 16:11)</a>:</h4>
<p>yeah you get into "pure" functions I guess :)</p>



<a name="197578757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197578757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197578757">(May 14 2020 at 16:12)</a>:</h4>
<p>ugh</p>



<a name="197578915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197578915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197578915">(May 14 2020 at 16:12)</a>:</h4>
<p>yea, I keep forgetting panicking counts as a side effect</p>



<a name="197588988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197588988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197588988">(May 14 2020 at 17:22)</a>:</h4>
<p>On <code>unwrap</code>: one could argue that <code>assert_matches!(x, Ok(_));</code> is better as a statement than <code>x.unwrap();</code>, or similar.  (Or that it's weird to care that it's ok without looking at the non-<code>()</code> value anyway.)</p>
<p>It's not unusual for must_use functions to possibly be able to panic.  For example, <code>split_off</code> can panic but is still <code>must_use</code>.</p>



<a name="197589682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197589682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197589682">(May 14 2020 at 17:27)</a>:</h4>
<p>I just wanted to point out that this approach to inferring must_use has false positives, I'm not taking any position about how important those are.</p>



<a name="197590256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197590256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197590256">(May 14 2020 at 17:31)</a>:</h4>
<p>(But indeed, <code>split_off</code> and many other functions are different from <code>unwrap</code> in that I've never seen a program call <code>split_off</code> etc. just to get its panic behavior.)</p>



<a name="197590840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197590840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197590840">(May 14 2020 at 17:36)</a>:</h4>
<p>FWIW <a href="https://github.com/rust-lang/rfcs/pull/2450">https://github.com/rust-lang/rfcs/pull/2450</a></p>



<a name="197590853"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/MustUse/near/197590853" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/MustUse.html#197590853">(May 14 2020 at 17:36)</a>:</h4>
<p>(truly, there is nothing new under the sun)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>